package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OaOrgUser;
import com.ruoyi.system.service.IOaOrgUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * oa组织人员 信息操作处理
 * 
 * @author ruoyi
 * @date 2020-03-10
 */
@Controller
@RequestMapping("/system/oaOrgUser")
public class OaOrgUserController extends BaseController
{
    private String prefix = "system/oaOrgUser";
	
	@Autowired
	private IOaOrgUserService oaOrgUserService;
	
	@RequiresPermissions("system:oaOrgUser:view")
	@GetMapping()
	public String oaOrgUser()
	{
	    return prefix + "/oaOrgUser";
	}
	
	/**
	 * 查询oa组织人员列表
	 */
	@RequiresPermissions("system:oaOrgUser:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(OaOrgUser oaOrgUser)
	{
		startPage();
        List<OaOrgUser> list = oaOrgUserService.selectOaOrgUserList(oaOrgUser);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出oa组织人员列表
	 */
	@RequiresPermissions("system:oaOrgUser:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OaOrgUser oaOrgUser)
    {
    	List<OaOrgUser> list = oaOrgUserService.selectOaOrgUserList(oaOrgUser);
        ExcelUtil<OaOrgUser> util = new ExcelUtil<OaOrgUser>(OaOrgUser.class);
        return util.exportExcel(list, "oaOrgUser");
    }
	
	/**
	 * 新增oa组织人员
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存oa组织人员
	 */
	@RequiresPermissions("system:oaOrgUser:add")
	@Log(title = "oa组织人员", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(OaOrgUser oaOrgUser)
	{		
		return toAjax(oaOrgUserService.insertOaOrgUser(oaOrgUser));
	}

	/**
	 * 修改oa组织人员
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		OaOrgUser oaOrgUser = oaOrgUserService.selectOaOrgUserById(id);
		mmap.put("oaOrgUser", oaOrgUser);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存oa组织人员
	 */
	@RequiresPermissions("system:oaOrgUser:edit")
	@Log(title = "oa组织人员", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(OaOrgUser oaOrgUser)
	{		
		return toAjax(oaOrgUserService.updateOaOrgUser(oaOrgUser));
	}
	
	/**
	 * 删除oa组织人员
	 */
	@RequiresPermissions("system:oaOrgUser:remove")
	@Log(title = "oa组织人员", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(oaOrgUserService.deleteOaOrgUserByIds(ids));
	}
	
}
